<%@ page contentType="text/html; charset=utf-8"%>
<script type="text/javascript">
$(function(){	
    $("#listOlder").jqGrid({
    	url:'workflow/data/query-data!history',
        datatype: "json",
        mtype: 'GET',
        colNames:['流程名','活动名','发起人','发起时间','最后办理人','状态','办理状态','表单','监控','回退'],
        colModel :[ 
        {name:'workflowName', index:'workflowName', width:150,formatter:nameFormater}, 
        {name:'actionName', index:'actionName', width:200} ,
        {name:'starter', index:'starter', width:150} ,
        {name:'startDate', index:'startDate', width:150 },
        {name:'owner', index:'owner', width:100 },
        {name:'state', index:'state', width:100 ,formatter:stateFormatter}, 
        {name:'status', index:'status', width:100 ,formatter:statusFormatter}, 
        {name:'workflowId', index:'workflowId', width:100,formatter:formFormatter} ,
        {name:'workflowId', index:'workflowId', width:100,formatter:doWatchFormatter }, 
        {name:'workflowId', index:'workflowId', width:200,formatter:rollbackFormatter } 
      ],
      pager:'#pagerOlder',
      rowNum:10,
      rowList:[10,20,30],
      sortname: 'lastSendDate',
      sortorder: 'desc',
      viewrecords: true,
      caption: '已办事项',
      width:'790',
      height:'300',
      jsonReader: {
  		repeatitems : false,
  		id: "0"
  	  }  
    }); 

    
    function nameFormater(cellvalue,optionss,rowObject){
    	return cellvalue+"["+rowObject['workflowId']+"]";
    }
    function statusFormatter(cellvalue,optionss,rowObject){
    	switch(cellvalue){
    	  case 'Finished':return '完成';
    	  case 'Underway':return '在办';
    	  default :return '未知';
    	}
    }

    function stateFormatter(cellvalue,optionss,rowObject){
         
         switch(cellvalue){
         case 0:return "开始";
         case 1:return "激活";
         case 2:return "挂起";
         case 3:return "中断";
         case 4:return "完成";
         case -1:return "未知";
         }

    }

    //回退操作
    function rollbackFormatter(cellvalue,options,rowObject){
         var user='${loginuser.username}';
         if(user==rowObject['owner'] && rowObject['state']==1){
             //当前用户是发起人,并且是待办状态
             var url = "rollbackwf.action?workflowId="+cellvalue;
             var link   = $("<a style='color:#fc3;'></a>");
             link.attr("href","javascript:doAjaxLink('"+url+"');");
             link.text("回退");  
             
             var url2 = "completewf.action?workflowId="+cellvalue;
             var link2 = $("<a style='color:green'></a>");
             link2.attr("href","javascript:doAjaxLink('"+url2+"');");
             link2.text("结束"); 
             
             var url3 = "deletewf.action?workflowId="+cellvalue;
             var link3 = $("<a style='color:red'></a>");
             link3.attr("href","javascript:doAjaxLink('"+url3+"');");
             link3.text("删除");
             var links = $("<span></span>");
             links.append(link.get(0));
             links.append("|");
             links.append(link2.get(0));
             links.append("|");             
             links.append(link3.get(0));
             return　links.html();
         }else{
             return "无权限";
         }


    }
     
   function formFormatter(cellvalue,options,rowObject){
    	 var param = {
               "workflowId":cellvalue,
               "workflowName":rowObject['workflowName'],
               "stepId":rowObject['stepId'],
               "showOnly":true
    	        };
        var url = 'showform.action?'+$.param(param);
    	
    	var link = $("<a onclick=\"openWithMask('"+url+"');return false;\"></a>");
        link.attr("href","javascript:;");
        link.addClass("nyroModal");        
        link.text("表单");
        return $("<span></span>").append(link).html();

    }
 
    function doWatchFormatter(cellvalue ,options,rowObject){
	      //alert(cellvalue);
	      var url  ="workflow/monitor.action?workflowId="+rowObject['workflowId'];
	      var link = $("<a onclick=\"doAjaxLink('"+url+"');return false;\"></a>");
	      link.attr("href","javascript:;");
	      link.text("监控");
	      return $("<span></span>").append(link).html();
    }    
    
  }); 
</script>
<div id="jqgridolder">
	<table id="listOlder"></table>
	<div id="pagerOlder"></div>
</div>